package fr.webeo.teambuilder.ao;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import fr.webeo.teambuilder.bo.Team;

/**
 * The class <strong>MyTeamTableModel</strong>.
 * 
 * @author Sébastien Bordes
 * @version $Revision$ $Date$ $Name$
 * 
 * @since fr.webeo.teambuilder 1.0
 */
public class MyTeamTableModel extends AbstractTableModel {

    /**
     * Comment for <code>serialVersionUID</code>
     */
    private static final long serialVersionUID = 4977804532229925764L;

    public static final int COL_TEAM = 0;
    public static final int COL_PLAYER_1 = 1;
    public static final int COL_PLAYER_2 = 2;
    public static final int COL_PLAYER_3 = 3;
    public static final int COL_PLAYER_4 = 4;
    public static final int COL_PLAYER_5 = 5;
    public static final int COL_PLAYER_6 = 6;
    public static final int COL_PLAYER_7 = 7;
    public static final int COL_PLAYER_8 = 8;
    public static final int COL_PLAYER_9 = 9;
    public static final int COL_PLAYER_10 = 10;

    public static final String NAME_COL_TEAM = "Equipe";
    public static final String NAME_COL_PLAYER = "Joueur ";

    /** . */
    private int teamMateNumberByTeam = 2;

    /** . */
    private List<Team> content;

    /**
     * 
     * @param v
     */
    public MyTeamTableModel(List<Team> teams) {
        setTeams(teams);
        // Collections.sort(content);
    }

    public void setTeams(List<Team> teams) {
        if (teams == null) {
            content = new ArrayList<Team>();
        } else {
            content = teams;
        }
        fireTableDataChanged();
    }

    public int getColumnCount() {
        return 1 + getTeamMateNumberByTeam();
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {

        case 0:
            return content.get(rowIndex).getName();

        default:
            if (content.get(rowIndex).getPlayers().size() >= columnIndex) {
                return content.get(rowIndex).getPlayers().get(columnIndex - 1);
            }

        }
        return null;
    }

    /*
     * public void setValueAt(Object aValue, int row, int column) { switch (column) { case 0: content.get(row).setReady(((Boolean) aValue) .booleanValue()); break;
     * 
     * case 1: content.get(row).setNom((String) aValue); break;
     * 
     * case 2: content.get(row).setPrenom((String) aValue); break;
     * 
     * case 3: content.get(row).setMail((String) aValue); break;
     * 
     * case 4: content.get(row).setEquipe((String) aValue); break;
     * 
     * case 5: content.get(row).setCoequipier((String) aValue); break; } fireTableCellUpdated(row, column); }
     */

    /**
	 * 
	 */
    @Override
    public boolean isCellEditable(int row, int column) {
        return false;
    }

    /**
	 * 
	 */
    @Override
    public Class getColumnClass(int columnIndex) {
        return String.class;
    }

    /**
	 * 
	 */
    @Override
    public String getColumnName(int column) {
        switch (column) {
        case 0:
            return NAME_COL_TEAM;

        default:
            return NAME_COL_PLAYER + column;
        }
    }

    /**
	 * 
	 */
    public int getRowCount() {
        return content.size();
    }

    /*
     * public void delete(int selectedRow) { content.remove(selectedRow); fireTableRowsDeleted(selectedRow, selectedRow); }
     */

    /**
     * @return Returns the teamMateNumberByTeam.
     */
    public int getTeamMateNumberByTeam() {
        return this.teamMateNumberByTeam;
    }

    /**
     * @param teamMateNumberByTeam The teamMateNumberByTeam to set.
     */
    public void setTeamMateNumberByTeam(int teamMateNumberByTeam) {
        this.teamMateNumberByTeam = teamMateNumberByTeam;
    }

}
